#include "TerrainContentsGeneratorBedWars.h"
#include <algorithm>
#include "Engine/MathUtils.hpp"

#include "Subsystems/SubsystemGameInfo.h"
#include "GameSingleton.h"

namespace BedWars
{
    TerrainContentsGeneratorBedWars::~TerrainContentsGeneratorBedWars()
    {
    }

    uint32_t TerrainContentsGeneratorBedWars::getOceanLevel()
    {
        return 0;
    }

    TerrainContentsGeneratorBedWars::TerrainContentsGeneratorBedWars()
    {
        subsystemGameInfo = GameSingleton::singletonPtr->getSingleton<SubsystemGameInfo>();
    }

    Vector3 TerrainContentsGeneratorBedWars::findCoarseSpawnPosition()
    {
        return FastVector3::Zero;
    }

    float TerrainContentsGeneratorBedWars::calculateOceanShoreDistance(float x, float z)
    {
        return 0;
    }

    float TerrainContentsGeneratorBedWars::calculateHeight(float x, float z)
    {
        return subsystemGameInfo->terrainLevel;
    }

    int32_t TerrainContentsGeneratorBedWars::calculateTemperature(float x, float z)
    {
        return MathUtils::Clamp<int32_t>(12 + (int32_t)subsystemGameInfo->temperatureOffset, 0, 15);
    }

    int32_t TerrainContentsGeneratorBedWars::calculateHumidity(float x, float z)
    {
        return MathUtils::Clamp<int32_t>(12 + (int32_t)subsystemGameInfo->humidityOffset, 0, 15);
    }

    float TerrainContentsGeneratorBedWars::calculateMountainRangeFactor(float x, float z)
    {
        return 0.0f;
    }

    void TerrainContentsGeneratorBedWars::generateChunkContentsPass1(TerrainChunk *chunk)
    {
        for (int32_t i = 0; i < 16; i++)
        {
            for (int32_t j = 0; j < 16; j++)
            {
                int32_t num = i + chunk->origin.posX;
                int32_t num2 = j + chunk->origin.posY;
                chunk->setTemperatureFast(i, j, calculateTemperature(num, num2));
                chunk->setHumidityFast(i, j, calculateHumidity(num, num2));
                int32_t num3 = TerrainChunk::CalculateCellIndex(i, 0, j);
                for (int32_t k = 0; k < 256; k++)
                {
                    chunk->setCellValueFast(num3 + k, 0);
                }
            }
        }
    }
    void TerrainContentsGeneratorBedWars::generateChunkContentsPass2(TerrainChunk *chunk) {}
    void TerrainContentsGeneratorBedWars::generateChunkContentsPass3(TerrainChunk *chunk) {}
    void TerrainContentsGeneratorBedWars::generateChunkContentsPass4(TerrainChunk *chunk) {}

}